﻿namespace TowerCraneMonitorClient.NetClient.LimitInfo
{
    /// <summary>
    /// 限位信息
    /// </summary>
    public class Entity : NetClient.Entity
    {
        /// <summary>
        /// 左转最大角度
        /// </summary>
        public float LeftAngleLimit { get; set; }

        /// <summary>
        /// 右转最大角度
        /// </summary>
        public float RightAngleLimit { get; set; }

        /// <summary>
        /// 小车前行最远点离塔臂前端的距离m。远限位
        /// </summary>
        public float RemoteLimit { get; set; }

        /// <summary>
        /// 小车回收最近点离塔臂前端的距离m。近限位
        /// </summary>
        public float NearLimit { get; set; }

        /// <summary>
        /// 吊钩起升的最高点离塔臂的距m。高度限位
        /// </summary>
        public float HighLimit { get; set; }

        /// <summary>
        /// 塔机支持的最大起重量t。重量限位
        /// </summary>
        public float WeightLimit { get; set; }

        /// <summary>
        /// 塔机最大幅度支持的最大起重量t。
        /// </summary>
        public float MaxExtentWeightLimit { get; set; }

        /// <summary>
        /// 力矩限位最大值。
        /// </summary>
        public float ForceLimit { get; set; }

        /// <summary>
        /// 预警百分比。
        /// </summary>
        public float EarlyWarningWeightPercent
        {
            get => earlyWarningWeightPercent;
            set
            {
                if (value < 0 || value > 100)
                    throw new PercentageArgumentOutOfRangeException(
                    nameof(EarlyWarningWeightPercent));
                earlyWarningWeightPercent = value;
            }
        }
        float earlyWarningWeightPercent;

        /// <summary>
        /// 报警百分比。
        /// </summary>
        public float AlarmWeightPercent
        {
            get => alarmWeightPercent;
            set
            {
                if (value < 0 || value > 100)
                    throw new PercentageArgumentOutOfRangeException(
                    nameof(AlarmWeightPercent));
                alarmWeightPercent = value;
            }
        }
        float alarmWeightPercent;

        /// <summary>
        /// 违章百分比。
        /// </summary>
        public float ViolationWeightPercent
        {
            get => violationWeightPercent;
            set
            {
                if (value < 0 || value > 100)
                    throw new PercentageArgumentOutOfRangeException(
                    nameof(ViolationWeightPercent));
                violationWeightPercent = value;
            }
        }
        float violationWeightPercent;

        /// <summary>
        /// 基于该对象生成 LimitInfo.Req 报文
        /// </summary>
        /// <param name="errorMessage">失败时返回错误信息，成功时返回 null</param>
        /// <returns>成功时返回 LimitInfo.Req 对象，失败时返回 null</returns>
        public new Req ToReq() => new Req(this);
    }
}
